package com.greenhouse.mapper.greenhouse;

import com.greenhouse.model.Greenhouse;
import com.greenhouse.request.EquipmentRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface GreenhouseMapper {
    /**
     * 查询用户大棚信息
     * @param userId
     * @return
     */
    List<Greenhouse> showGreenhousesByUserId(Integer userId);
    /**
     * 查询大棚id及名称
     * @param userId
     * @return
     */
    @Select("select id as greenhouseId,name as greenhouseName from greenhouse where user_id = #{userId}")
    List<EquipmentRequest> showGreenhouseIdAndName(Integer userId);

    /**
     * 修改大棚信息
     * @return
     */
    Integer updateGreenhouses(Greenhouse greenhouse);

    /**
     * 添加大棚信息
     * @return
     */
    @Insert("insert into greenhouse " +
            "(user_id,name,location,area,status,create_time) " +
            "values " +
            "(#{userId},#{name},#{location},#{area},0,NOW())")
    Integer insertGreenhouse(Integer userId, String name, String location, Integer area);

    /**
     * 删除大棚数据
     * @param id
     * @return
     */
    @Delete("delete from greenhouse where id = #{id}")
    Integer deleteGreenhouse(Integer id);

    /**
     * 查询大棚信息
     * @param name
     * @param userId
     * @return
     */
    Greenhouse getGreenhouse(String name, Integer userId);
    /**
     * 修改大棚状态
     */
    @Update("update greenhouse set status = #{status} where id = #{id}")
    Integer updateGreenhouseStatus(@Param("id") Integer id, @Param("status") Integer status);
}
